
(function(){

  App.Type.Tech.create = function(id){
    var name;
    var techType;
    var m;

    if (m = id.match(/^(?:[^\/]*\/)*(.+?)\.([\w\.]+)$/))
    {
      name = m[1]
      techType = App.Type.TechType.get(m[2]);
      if (!techType)
        throw 'Unknown tech type - `' + m[2] + '`';
    }
    else
      throw 'Can\'t determine tech type for ' + id;

    var content = techType.data.template.format({
      name: name,
      indent: '    '
    });
    var pos = Math.max(content.indexOf('|'), 0);

    return App.Type.Tech({
      id: id,
      type: techType.data.id,
      content: content.replace(/\|/, ''),
      lastPos: pos
    });
  }

})();